<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Vue的常见指令v-if,v-show,v-for</title>
    <script src="../../assets/vue.js"></script>
</head>
<body>
    <div id="root">
        <div v-if="show">使用v-if</div>
        <div v-else>v-if的else</div>
        <div v-show="show">使用v-show</div>
        <button @click="handleClick">toggle</button>
        <hr>
        <h4>数组循环</h4>
        <ul id="example-1">
            <li v-for="(item, index) in items" :key="item.id">
                {{ item.message }}
            </li>
        </ul>
        <hr>
        <h4>对象渲染</h4>
        <details>在遍历对象时，是按 Object.keys() 的结果遍历，但是不能保证它的结果在不同的 JavaScript 引擎下是一致的。</details>
        <ul id="v-for-object" class="demo" >
            <li v-for="(value, key, index) in object" :key="key">
                {{ value }}
            </li>
        </ul>
    </div>
    <script>
        new Vue({   
            el: '#root',
            data:{
                show: true,
                items: [
                    { id:1, message: 'Foo' },
                    { id:2, message: 'Bar' }
                ],
                object: {
                    firstName: 'John',
                    lastName: 'Doe',
                    age: 30
                }
            },
            methods: {
                handleClick: function() {
                    this.show = !this.show
                }
            }
        })
    </script>
</body>
</html>